ErrorBoundary   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A getDerivedStateFromError 0 4 1
A render 0 17 2
A componentDidCatch 0 4 1
1
import { Component, ReactNode } from 'react'
2
import { Button, Text } from 'shared/ui'
3
4
interface IState {
5
  error: null | Error
6
}
7
8
interface IProps {
9
  children: ReactNode
10
}
11
12
class ErrorBoundary extends Component<IProps, IState> {
0 ignored issues
show
introduced by
Component is not optimized. Please add a shouldComponentUpdate method.
Loading history...
13
  state = { error: null }
0 ignored issues
show
introduced by
State initialization should be in a constructor
Loading history...
introduced by
state should be placed after getDerivedStateFromError
Loading history...
14
15
  static getDerivedStateFromError(error: Error) {
16
    return { error }
17
  }
18
19
  componentDidCatch(error: Error, errorInfo: any) {
0 ignored issues
show
introduced by
Unexpected any. Specify a different type.
Loading history...
20
    console.error('From ErrorBoundary:', error, errorInfo)
21
  }
22
23
  render() {
24
    if (this.state.error) {
0 ignored issues
show
introduced by
Must use destructuring state assignment
Loading history...
25
      return (
26
        <div className="flex flexCol flexAlCent">
0 ignored issues
show
introduced by
Expected indentation of 10 space characters but found 8.
Loading history...
introduced by
JSX not allowed in files with extension '.tsx'
Loading history...
27
          <Text className="mb32 mt32" tag="h2">
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
Prop "className" is forbidden on Components
Loading history...
introduced by
Prop tag must be placed on a new line
Loading history...
introduced by
Expected indentation of 14 space characters but found 12.
Loading history...
28
            Something went wrong
29
          </Text>
30
          <Button onClick={() => window.history.go()}>
0 ignored issues
show
introduced by
Expected indentation of 12 space characters but found 10.
Loading history...
introduced by
JSX element should start in a new line
Loading history...
introduced by
JSX props should not use arrow functions
Loading history...
introduced by
JSX attribute values should not contain functions created in the same scope
Loading history...
31
            <Text tag="span">Refresh Page</Text>
0 ignored issues
show
introduced by
Expected indentation of 14 space characters but found 12.
Loading history...
introduced by
Refresh Page must be placed on a new line
Loading history...
32
          </Button>
33
        </div>
34
      )
35
    }
36
37
    return this.props.children
0 ignored issues
show
introduced by
Must use destructuring props assignment
Loading history...
38
  }
39
}
40
41
export { ErrorBoundary }
42